package cc.messcat.dao.fupin;

import java.math.BigInteger;
import java.util.List;
import java.util.Map;

import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;

import cc.messcat.common.dao.BaseDaoImpl;
import cc.messcat.common.dao.BaseHibernateDaoUtil;
import cc.messcat.entity.fupin.Company;
import cc.messcat.entity.fupin.VisionPoolFamily;
import cc.messcat.entity.vo.CompanyVo;
import cc.messcat.entity.vo.PoorFamilyVo;

@Repository
public class CompanyDaoImpl extends BaseDaoImpl<Company> implements CompanyDao {

	@Override
	public List<CompanyVo> getCompanyVo(Integer pageNo, Integer pageSize, String sql, Map map) {
		int pageStart = (pageNo - 1) * pageSize;
		List list = getCurrentSession().createSQLQuery(sql).setProperties(map).setFirstResult(pageStart).setMaxResults(pageSize).setResultTransformer(Transformers.aliasToBean(CompanyVo.class)).list();
		return list;
	}

	@Override
	public int getCount(String sql, Map map ) {
		BigInteger rows = (BigInteger)getCurrentSession().createSQLQuery(sql).setProperties(map).uniqueResult();
		return rows.intValue();
	}

	
	public List<CompanyVo> queryCompanyFamilyById(String sql) {
		List list = getCurrentSession().createSQLQuery(sql).setResultTransformer(Transformers.aliasToBean(CompanyVo.class)).list();
		return list;
	}

	@Override
	public void executeUpdateById(String sql) {
		getCurrentSession().createSQLQuery(sql).executeUpdate();
	}

}
